<?php
class UserModel extends Model {
	protected $_validate = array(
			array('user_email','require','请输入邮箱'),
			array('user_email','email','邮箱格式错误'),
			array('user_email','','邮箱已存在',0,'unique',1),
			array('user_nickname','require','请输入昵称'),
			array('user_nickname','3,13','昵称长度3-13位',0,'length'),
			array('user_password','require','请输入密码'),
			array('user_password','6,18','密码长度6-18位',0,'length'),
	);
	
	protected $_auto = array(
			array('user_password','md5',1,'function'),
			array('user_register_time','time',1,'function'),	
			array('user_register_ip','get_client_ip',1,'function'),
			array('user_last_logintime','time',1,'function'),
			array('user_last_loginip','get_client_ip',1,'function'),
			array('user_add_times','0'),
			array('user_email_verify','0'),
			array('user_advance','0'),
			array('user_advance_time','0'),
			array('user_status','1'),
	);
	
	//登录之后更新登录次数，登录IP，登录时间
	public function updateLogin(){
		$sql = 'UPDATE __TABLE__ SET user_last_logintime = '.time().', user_last_loginip = "'.get_client_ip().'", user_login_times = user_login_times + 1 WHERE user_id = '.$_SESSION['user']['user_id'];
		return $this->execute($sql);
	}
}